module.exports = app => {
  const { INTEGER, STRING } = app.Sequelize;
  const Order = app.model.define("order", {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    order_no: STRING,
    order_state: { type: INTEGER, allowNull: false },
    logistics: STRING,
    quantity: INTEGER
  });

  Order.associate = function () {
    app.model.Order.belongsTo(app.model.User, {
      foreignKey: "user_id",
      as: "user"
    });
    app.model.Order.belongsTo(app.model.Commodity, {
      foreignKey: "shop_id",
      as: "shop"
    });
    app.model.Order.belongsTo(app.model.UserInfo, {
      foreignKey: "userInfo_id",
      as: "userInfo"
    });
  };
  return Order;
};
